<template>
  <div>
    <div class="content" @click="show(item.id)" v-for="item in newsList" :key="item.id">
      <div class="img-con">
        <img :src="item.img_url" alt="">
      </div>
      <div class="text-con">
        <div class="title">{{item.title}}</div>
        <div class="info">
          <span>发表时间：{{item.add_time}}</span>
          <span>点击：{{item.click}}次</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      newsList: []
    }
  },
  created() {
    this.getNewsList()
  },
  methods: {
    // 查询新闻资讯列表
    getNewsList() {
      this.$http.get('news/list').then(res => {
        // 这里变成 0 是成功了
        if (res.data.status === 0) {
          this.newsList = res.data.message
          console.log(this.newsList);
        } else {
          this.$toast('新闻资讯获取失败')
        }
      })
    },
    // 查看详细信息
    show(id) {
      this.$router.push({name: 'news_info', params: {id}})
      // this.$router.push('/news/info/'+id)
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  font-size: 14px;
  .img-con {
    width: 45px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .text-con {
    padding-left: 10px;
    width: 100%;
    overflow: hidden;
    .title {
      font-weight: 700;
      // 不换行，直到遇到<br>
      white-space: nowrap;
      // 文字溢出时显示 '...'
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .info {
      font-size: 12px;
      color: #26a2ff;
      display: flex;
      justify-content: space-between;
    }
  }
}
</style>